package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Freight;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.EnquiryQuery;
import com.by.query.HEnquiryQuery;
import com.by.query.OfferQuery;
import com.by.service.FreightService;
import com.by.service.HEnquiryService;
import com.by.service.OfferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "货代管理")
@RequestMapping("/v1")
public class FreightController extends BaseController {
    @Autowired
    FreightService freightService;
    @Autowired
    HEnquiryService hEnquiryService;
    @Autowired
    OfferService offerService;

    @ApiOperation("询价单列表")
    @PostMapping("/freight/query")
    public ResultBean queryAll(@RequestBody HEnquiryQuery query) {
        query.setTransportway(freightService.selectTransportation(Integer.parseInt(query.getCreateUserId())));
        Map map = BeanUtil.beanToMap(query);
        PageBean bean = hEnquiryService.query(map);
        return success("询价单列表", bean);
    }
    @ApiOperation("报价单列表")
    @PostMapping("/offer/query")
    public ResultBean queryAll(@RequestBody OfferQuery query) {
        Map map = BeanUtil.beanToMap(query);
        PageBean bean = offerService.query(map);
        return success("报价单列表", bean);
    }
}
